package com.lianniu.mgr.teaProduct.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.teaPic.dao.TeaProductPicDao;
import com.lianniu.mgr.teaPic.model.TeaProductPic;
import com.lianniu.mgr.teaProduct.dao.TeaProductDao;
import com.lianniu.mgr.teaProduct.model.TeaCount;
import com.lianniu.mgr.teaProduct.model.TeaProduct;
import com.lianniu.mgr.teaProduct.service.ITeaProductService;

@Service
@Transactional
public class TeaProductServiceImpl implements ITeaProductService{

	private final static Logger logger = Logger.getLogger(TeaProductServiceImpl.class);

	@Resource
	private TeaProductDao teaProductDao;
	
	@Autowired
	private TeaProductPicDao teaProductPicDao;
	
	/**
	 * 获取商品列表
	 * 
	 * @return
	 */
	@Override
	public BaseResult getTeaProductList(Map param) {
		logger.info("TeaProductServiceImpl getTeaProductList start");
		List<TeaProduct> teaProductList = teaProductDao.selectProductListByParam(param);
		if (!CollectionUtils.isEmpty(teaProductList)) {
			for (TeaProduct teaProduct : teaProductList) {
				
			}
		}
		logger.info("TeaProductServiceImpl getTeaProductList end");
		return BaseResult.success(teaProductList);
	}

	/**
	 * 获取共交易的茶园总量
	 * @return
	 */
	@Override
	public BaseResult getTeaCount() {
		logger.info("TeaProductServiceImpl getTeaCount start");
		Float teaCount = teaProductDao.getTeaCount();
		Float teaSuccessCount = teaProductDao.getTeaSuccessCount();
		logger.info("TeaProductServiceImpl getTeaCount end");
		TeaCount tea = new TeaCount();
		tea.setTeaCount(teaCount);
		tea.setTeaSuccessCount(teaSuccessCount);
		return BaseResult.success(tea);
	}
	
	/**
	 * 根据商品id获取当前商品的详细信息
	 * @return
	 */
	@Override
	public BaseResult getTeaProductInfo(Long productId) {
		logger.info("TeaProductServiceImpl getTeaProductInfo start");
		TeaProduct teaProductInfo = teaProductDao.selectByPrimaryKey(productId);
		if(teaProductInfo!=null){
			TeaProductPic productPic = teaProductPicDao.selectByPrimaryKey(teaProductInfo.getPicid());
			teaProductInfo.setProductPic(productPic);
		}
		logger.info("TeaProductServiceImpl getTeaProductInfo end");
		return BaseResult.success(teaProductInfo);
	}
	
	
	/**
	 *查询我的收藏
	 * 
	 * @return
	 */
	@Override
	public BaseResult getTeaProductListByCollection(Map param) {
		logger.info("TeaProductServiceImpl getTeaProductList start");
		List<TeaProduct> teaProductList = teaProductDao.getTeaProductListByCollection(param);
		if (!CollectionUtils.isEmpty(teaProductList)) {
			for (TeaProduct teaProduct : teaProductList) {
				
			}
		}
		logger.info("TeaProductServiceImpl getTeaProductList end");
		return BaseResult.success(teaProductList);
	}
}
